<?php
/**
 * Created by lzl
 * Date: 2021 2021/11/18
 * Time: 10:10
 */
namespace App\Forms;


use App\Models\PartnerOrder;
use Illuminate\Database\Query\Builder;

class PartnerForms extends BaseForm
{

    /**
     * @param $validated
     * @return PartnerOrder|\Illuminate\Database\Eloquent\Model
     */
    public function createOrder($validated)
    {
        return PartnerOrder::create($validated);
    }


    public function getOrderList($validated)
    {
        $list = PartnerOrder::where(function($q) use ($validated){
            /**
             * @var Builder $q
             */
            if(isset($validated['status']) && $validated['status']){
                $q->where('status', $validated['status']);
            }

            if(isset($validated['order_sn']) && $validated['order_sn'] ){
                $q->where('order_sn', $validated['order_sn']);
            }

            return $q;
        })->page(function($q) use ($validated){

            if(isset($validated['page']) && isset($validated['limit'])){
                $q->page($validated['page'], $validated['limit']);
            }

            return $q;
        })->orderBy('id','desc')->get()->toArray();


        return $list;
    }

}